package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.TransportManageDepRel;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.TransportManageDepRelDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2022-01-28 11:16:02
 */
public class TransportManageDepRelConverts {

    private static Logger LOG = LoggerFactory.getLogger(TransportManageDepRelConverts.class);

    public static List<TransportManageDepRelDTO> convert(List<TransportManageDepRel> transportManageDepRelList) {
        if (CollectionUtils.isEmpty(transportManageDepRelList)) {
            return Collections.EMPTY_LIST;
        }

        List<TransportManageDepRelDTO> transportManageDepRelListResult = Lists.newArrayList();
        for (TransportManageDepRel transportManageDepRel : transportManageDepRelList) {
            transportManageDepRelListResult.add(convert(transportManageDepRel));
        }
        return transportManageDepRelListResult;
    }

    public static TransportManageDepRelDTO convert(TransportManageDepRel transportManageDepRel) {
        try {
            return BeanUtils.copy(transportManageDepRel, TransportManageDepRelDTO.class);
        } catch (Exception e) {
            LOG.error("TransportManageDepRel到TransportManageDepRelDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "TransportManageDepRel到TransportManageDepRelDTO转换失败", e);
        }
    }

    public static TransportManageDepRel convert(TransportManageDepRelDTO transportManageDepRelDTO) {
        try {
            return BeanUtils.copy(transportManageDepRelDTO, TransportManageDepRel.class);
        } catch (Exception e) {
            LOG.error("TransportManageDepRelDTO到TransportManageDepRel转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "TransportManageDepRelDTO到TransportManageDepRel转换失败", e);
        }
    }
}